# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=sphinx_rtd_theme
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.1.9
pkgrel=1
pkgdesc="Python Sphinx Read The Docs Theme (mingw-w64)"
arch=('any')
license=('MIT')
url='https://github.com/snide/sphinx_rtd_theme'
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
options=('staticlibs')
source=("https://pypi.python.org/packages/source/s/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('273846f8aacac32bf9542365a593b495b68d8035c2e382c9ccedcac387c9a0a1')

prepare() {
  cd ${srcdir}
  cp -r ${_realname}-${pkgver} python2-build
  cp -r ${_realname}-${pkgver} python3-build
}

build() {
  cd "${srcdir}"
  for builddir in python{2,3}-build; do
    pushd ${builddir}
    ${MINGW_PREFIX}/bin/${builddir%-build} setup.py build
    popd
  done
}

check() {
  cd "${srcdir}"
  for builddir in python{2,3}-build; do
    pushd ${builddir}
    ${MINGW_PREFIX}/bin/${builddir%-build} py.test
    popd
  done
}

package_python2-sphinx_rtd_theme() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd "${srcdir}/python2-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/COPYING"
}

package_python3-sphinx_rtd_theme() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-build"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/COPYING"
}

package_mingw-w64-i686-python2-sphinx_rtd_theme() {
  package_python2-sphinx_rtd_theme
}

package_mingw-w64-i686-python3-sphinx_rtd_theme() {
  package_python3-sphinx_rtd_theme
}

package_mingw-w64-x86_64-python2-sphinx_rtd_theme() {
  package_python2-sphinx_rtd_theme
}

package_mingw-w64-x86_64-python3-sphinx_rtd_theme() {
  package_python3-sphinx_rtd_theme
}
